package com.album.activity.adapter;

 
import java.lang.ref.SoftReference;
import java.util.ArrayList;
import java.util.List;  

import com.album.R;
import com.album.common.Constants;
   

import android.content.Context;  
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;  
import android.view.View;  
import android.view.ViewGroup;  
import android.widget.BaseAdapter;  
import android.widget.ImageView;  
import android.widget.RelativeLayout;
import android.widget.TextView;  
  
/** 
 * Copyright (C) 2010,Under the supervision of China Telecom Corporation Limited 
 * Guangdong Research Institute The New Vphone Project 
 *  
 * @Author fonter.yang 
 * @Create date：2010-10-11 
 *  
 */  
public class PhotopwdAdapter extends BaseAdapter {  
  
    private class GridHolder {  
        ImageView appImage;  
        TextView appName;  
    }  
  
    private Context context;  
  
    private LayoutInflater mInflater;  

    private List<Bitmap> list =new ArrayList<Bitmap>();
	
    public PhotopwdAdapter(Context c,List<Bitmap> datalist) {   
        this.context = c;  
        mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        if(datalist!=null){
            list = datalist; 
        }
    }   
    
    public void resletDataSetChanged(){
    	if(list!=null && list.size()>0)
    		list.clear();
    		list = null; 
    }
    
    public void setListDataSetChanged(Bitmap bitmap){ 
		list.add(bitmap);
    	notifyDataSetChanged();
    }
    public int getCount() {  
        // TODO Auto-generated method stub  
        return list.size();  
    }  
  
    @Override  
    public Object getItem(int index) {  
  
        return list.get(index);  
    }  
  
    @Override  
    public long getItemId(int index) {  
        return index;  
    }  
  
    @Override  
    public View getView(int index, View convertView, ViewGroup parent) { 

        GridHolder holder;  
        if (convertView == null) {     
            convertView = mInflater.inflate(R.layout.expandablegrid_item, null);     
            holder = new GridHolder();  
            holder.appImage = (ImageView)convertView.findViewById(R.id.itemImage); 
            holder.appImage.setLayoutParams(new RelativeLayout.LayoutParams(Constants.m_screenWidth,Constants.m_screenWidth));
            convertView.setTag(holder);     
        }else{  
             holder = (GridHolder) convertView.getTag();
        }  
        Bitmap bitmap = list.get(index);
        if(bitmap!=null){
            holder.appImage.setImageBitmap(bitmap);
//        	BitmapDrawable bitmapDrawable = new BitmapDrawable(bitmap);
//            holder.appImage.setBackgroundDrawable((Drawable)bitmapDrawable); 
        }else{
        	holder.appImage.setImageResource(R.drawable.icon);
        }
//        if (bitmap != null && bitmap.isRecycled() == false) {
//        	bitmap.recycle();
//        	bitmap = null;
//		}
        return convertView;  
    }  
  
}  
